<?		
	abstract class Controller
	{		
		public $routeData;
		public $routeValues;
		public $culture;
		public $words = array();
		
		function __construct($routeData, $routeValues)
		{
			$this->routeData = $routeData;
			$this->routeValues = $routeValues;
			
			
			if(isset($routeData['culture']))
			{
				$cultureFile = 'lib/locales/' . $routeData['culture'] . '.php';
				
				if(is_file($cultureFile))
				{
					include_once($cultureFile);
					
					$this->words = $words;
				}
			}
		}
		
		final function action_begin($action)
		{
		}
		
		final function action_end($action)
		{		
		}
		
		protected function json($model = null)
		{
			header("HTTP/1.0 200 OK");
			header("Cache-Control: no-cache, must-revalidate"); 
			header("Pragma: no-cache");
			header('Content-Type: application/json; charset=utf-8');
			
			print json_encode($model);
		}

		protected function ok($model = null)
		{
		    $result = array('success' => true);

            if(isset($model))
            {
                 $result['data'] = $model;
            }

            return $this->json($result);
		}

        protected function jsonp($model = null)
        {
            header("HTTP/1.0 200 OK");
            header("Cache-Control: no-cache, must-revalidate");
            header("Pragma: no-cache");
			header('Content-Type: application/json; charset=utf-8');

            print $_GET['callback'] . "(" . json_encode($model) . ")";
        }
		
		protected function view($model = array(), $name = null)
		{
			if(empty($name))
			{
				$name = $this->routeData['controller'] . '/' . $this->routeData['action'];
			}
			
			if(empty($model['title']))
			{
				$model['title'] = 'undefined';
			}
			
			$view = new View($model, $this, $name);
			$view->build();
		}
	}
?>